package com.conan.app.dailyflickr.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;

public class PrefUtils {
    private static String SHARED_PREF_NAME = "SHARED_PREF_NAME";
    
    public static void putStringSharedPref(Context context, String key, String value) {
        putStringPref(context, SHARED_PREF_NAME, key, value);
    }
    
    public static void putIntSharedPref(Context context, String key, int value) {
        putIntPref(context, SHARED_PREF_NAME, key, value);
    }
    
    public static void putLongSharedPref(Context context, String key, long value) {
        putLongPref(context, SHARED_PREF_NAME, key, value);
    }
    
    public static void putBooleanSharedPref(Context context, String key, boolean value) {
        putBooleanPref(context, SHARED_PREF_NAME, key, value);
    }
    
    public static String getStringSharedPref(Context context, String key, String defValue) {
        return getStringPref(context, SHARED_PREF_NAME, key, defValue);
    }
    
    public static int getIntSharedPref(Context context, String key, int defValue) {
        return getIntPref(context, SHARED_PREF_NAME, key, defValue);
    }
    
    public static long getLongSharedPref(Context context, String key, long defValue) {
        return getLongPref(context, SHARED_PREF_NAME, key, defValue);
    }
    
    public static boolean getBooleanSharedPref(Context context, String key, boolean defValue) {
        return getBooleanPref(context, SHARED_PREF_NAME, key, defValue);
    }
    /********************************************************************************************/
    public static void clearParamsSharedPref(Context context, String key1, String key2, String key3) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(SHARED_PREF_NAME, 0);
        Editor edit = pref.edit();
        edit.putString(key1, "");
        edit.putString(key2, "");
        edit.putString(key3, "");
        edit.remove(key1).remove(key2).remove(key3);
        edit.commit();
    }
    
    public static void putStringParamsSharedPref(Context context, String key1, String value1,
            String key2, String value2, String key3, String value3) {
        putStringParamsPref(context, SHARED_PREF_NAME, key1, value1, key2, value2, key3, value3);
    }
    public static void putStringParamsPref(Context context, String prefName, String key1, String value1,
            String key2, String value2, String key3, String value3) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        Editor editor = pref.edit().putString(key1, value1);
        if(!TextUtils.isEmpty(key2)){
            editor.putString(key2, value2);
        }
        if(!TextUtils.isEmpty(key3)){
            editor.putString(key3, value3);
        }
        editor.commit();
    }
    
    public static void putStringPref(Context context, String prefName, String key, String value) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        pref.edit().putString(key, value).commit();
    }
    
    public static void putIntPref(Context context, String prefName, String key, int value) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        pref.edit().putInt(key, value).commit();
    }
    
    public static void putLongPref(Context context, String prefName, String key, long value) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        pref.edit().putLong(key, value).commit();
    }
    
    public static void putBooleanPref(Context context, String prefName, String key, boolean value) {
        if(context == null) return;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        pref.edit().putBoolean(key, value).commit();
    }
    
    public static String getStringPref(Context context, String prefName, String key, String defValue) {
        if(context == null) return defValue;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        return pref.getString(key, defValue);
    }
    
    public static int getIntPref(Context context, String prefName, String key, int defValue) {
        if(context == null) return defValue;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        return pref.getInt(key, defValue);
    }
    
    public static long getLongPref(Context context, String prefName, String key, long defValue) {
        if(context == null) return defValue;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        return pref.getLong(key, defValue);
    }
    
    public static boolean getBooleanPref(Context context, String prefName, String key, boolean defValue) {
        if(context == null) return defValue;
        SharedPreferences pref = context.getSharedPreferences(prefName, 0);
        return pref.getBoolean(key, defValue);
    }
}
